package catwork::Controller::Mobile::Demo;
use Moose;
use namespace::autoclean;

BEGIN {extends 'Catalyst::Controller'; }

=head1 NAME

catwork::Controller::Mobile::Demo - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut


=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    $c->response->body('Matched catwork::Controller::Mobile::Demo in Mobile::Demo.');
}

=head2 mobile

is called on every mobile action

=cut

sub mobile :Chained('/') :PathPart('m') :CaptureArgs(0) {

   my ($self, $c ) = @_;
   $c->stash->{current_view} = "Mobile";

}

=head2 list

this function returns a json structure representing our lib folder;

=head3 source code

=cut

sub list :Chained('mobile') :PathPart('demo/lamp') :Args(0) {

    my ($self, $c) = @_;
    my $status = $c->request->{parameters}->{status};

    if($status eq "on") {
        $c->model('Demo')->mq_write($c, "set lamp on");
        $c->stash(
            status       => "on",
        );
    }
    elsif ($status eq "off") {
        $c->model('Demo')->mq_write($c, "set lamp off");
        $c->stash(
            status       => "off",
        );
    }

    $c->stash->{template} = 'demo/lamp.tt2';

}


=head1 AUTHOR

A clever guy

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
